package com.lovely602.ai.hello.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * kimi AI对话
 *
 * @author lizhixing
 */
@Slf4j
@RestController
public class OpenAIController {


    @Autowired
    private OpenAiChatModel openAiChatModel;

    @GetMapping("/chat")
    public String chat(@RequestParam(value = "msg", required = true) String msg) {

        String result = "";
        try {
            result = openAiChatModel.call(msg);
        } catch (Exception e) {
            log.error("chat error: ", e);
            result = e.getMessage();
        }

        return result;
    }

}
